/*
 * @Author: Drc
 * @Date: 2020-06-17 13:54:02
 * @LastEditors: Drc
 * @LastEditTime: 2021-11-01 18:30:16
 */
import System from '@path/config/system'
import Theme from '@path/config/theme'
import Locale from '@path/locale'
import React, {useCallback} from 'react'
import {Platform, Text, TextProps} from 'react-native'
import {RFValue} from 'react-native-responsive-fontsize'

interface ThemeTextProps extends TextProps {
  children: any
}

const ThemeText = (props: ThemeTextProps) => {
  const {children, style, ...other} = props

  //字体粗细映射fontFamily
  const _transFontFamily = useCallback(() => {
    const fontWeight = style?.fontWeight

    switch (Locale.currentLocale) {
      case 'zh':
        return
      case 'en':
        return
      default:
        return
    }
  }, [style?.fontWeight])

  return (
    <Text
      {...other}
      style={{
        color: Theme.getThemeColor('text_main'),
        paddingVertical: 0,
        includeFontPadding: false,
        ...style,
        fontSize: RFValue(style?.fontSize ?? 14, System.height),
        fontWeight: Platform.OS === 'android' ? 'normal' : style?.fontWeight,
        ...(_transFontFamily() ? {fontFamily: _transFontFamily()} : {}),
      }}>
      {children}
    </Text>
  )
}

export default ThemeText
